package common

import (
	"reflect"
)

/**
将struct 转为map 利用反射比中间转json性能好点
*/

func StructToMap(s interface{}) map[string]interface{} {
	var (
		m      map[string]interface{}
		i      int
		sType  reflect.Type
		sValue reflect.Value
	)

	m = make(map[string]interface{})

	sType = reflect.TypeOf(s)
	sValue = reflect.ValueOf(s)

	for i = 0; i < sType.NumField(); i++ {
		m[sType.Field(i).Name] = sValue.Field(i).Interface()
	}
	return m
}
